package com.yidian.controller.goods;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yidian.entity.PageResult;
import com.yidian.entity.Result;
import com.yidian.pojo.goods.Brand;
import com.yidian.server.goods.BrandService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author whb
 * @create 2021-05-06 17:46
 */
@RestController
@RequestMapping("/brand")
public class BrandController {
    @Reference
    private BrandService brandService;

    @RequestMapping("/findAll")
    public List<Brand> findAll(){
        return brandService.findAll();
    }

    @GetMapping("/findPage")
    public PageResult<Brand> findPage(int page,int size){
        return brandService.findPage(page,size);
    }

    @PostMapping("/findCondition")
    public List<Brand> findCondition(@RequestBody Map<String,Object> searchMap){
        return brandService.findCondition(searchMap);
    }

    @PostMapping("/findConditionAndPage")
    public PageResult<Brand> findConditionAndPage(@RequestBody Map<String,Object> searchMap,int page,int size){
        return brandService.findConditionAndPage(searchMap,page,size);
    }

    @GetMapping("/findById")
    public Brand findById(Integer id){
        return brandService.findById(id);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Brand brand){
        brandService.add(brand);
        return new Result(0,"商品添加成功！");
    }

    @PostMapping("/update")
    public Result update(@RequestBody Brand brand){
        brandService.update(brand);
        return new Result(0,"商品修改成功！");
    }

    @GetMapping("/delete")
    public Result delete(Integer id){
        brandService.delete(id);
        return new Result(0,"商品删除成功！");
    }

    @RequestMapping("/exception")
    public void testException(){
        int i=1/0;
    }
}